<?php

namespace App\Admin\Actions\Auction;

use App\Library\Logic\AuctionLogic;
use App\Library\Logic\MediaRelationLogic;
use App\Library\Logic\OperateLogLogic;
use App\Library\Models\AdminAuctionModel;
use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Exception;

class AuctionCopyAction extends RowAction
{
    public $name = '复制';

    /**
     * handle
     * @param AdminAuctionModel $model
     * @return Response
     * @throws Exception
     */
    public function handle(AdminAuctionModel $model): Response
    {
        AuctionLogic::copy($model, Admin::user()->user_id);
        OperateLogLogic::add(Admin::user()->user_id, 'admin.auction.copy', ['id' => $model->id]);
        return $this->response()->success('操作成功')->refresh();
    }

    /**
     * dialog
     * @return void
     */
    public function dialog(): void
    {
        $this->confirm('确定复制吗?');
    }
}
